/**
 */
package proyecto.testcasetool.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import proyecto.testcasetool.Actor;
import proyecto.testcasetool.AlternativeFlow;
import proyecto.testcasetool.BasicFlow;
import proyecto.testcasetool.TestcasetoolFactory;
import proyecto.testcasetool.TestcasetoolPackage;
import proyecto.testcasetool.UseCase;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Use Case</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getName <em>Name</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getDescription <em>Description</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getAlternativeFlow <em>Alternative Flow</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getBasicScenario <em>Basic Scenario</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getParticipantActor <em>Participant Actor</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getPreCondition <em>Pre Condition</em>}</li>
 *   <li>{@link proyecto.testcasetool.impl.UseCaseImpl#getPostCondition <em>Post Condition</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class UseCaseImpl extends EObjectImpl implements UseCase {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected static final String DESCRIPTION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDescription() <em>Description</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDescription()
	 * @generated
	 * @ordered
	 */
	protected String description = DESCRIPTION_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAlternativeFlow() <em>Alternative Flow</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAlternativeFlow()
	 * @generated
	 * @ordered
	 */
	protected EList<AlternativeFlow> alternativeFlow;

	/**
	 * The cached value of the '{@link #getBasicScenario() <em>Basic Scenario</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBasicScenario()
	 * @generated
	 * @ordered
	 */
	protected BasicFlow basicScenario;

	/**
	 * The cached value of the '{@link #getParticipantActor() <em>Participant Actor</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParticipantActor()
	 * @generated
	 * @ordered
	 */
	protected EList<Actor> participantActor;

	/**
	 * The default value of the '{@link #getPreCondition() <em>Pre Condition</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPreCondition()
	 * @generated
	 * @ordered
	 */
	protected static final String PRE_CONDITION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getPreCondition() <em>Pre Condition</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPreCondition()
	 * @generated
	 * @ordered
	 */
	protected String preCondition = PRE_CONDITION_EDEFAULT;

	/**
	 * The default value of the '{@link #getPostCondition() <em>Post Condition</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPostCondition()
	 * @generated
	 * @ordered
	 */
	protected static final String POST_CONDITION_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getPostCondition() <em>Post Condition</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPostCondition()
	 * @generated
	 * @ordered
	 */
	protected String postCondition = POST_CONDITION_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UseCaseImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TestcasetoolPackage.Literals.USE_CASE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDescription(String newDescription) {
		String oldDescription = description;
		description = newDescription;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__DESCRIPTION, oldDescription, description));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<AlternativeFlow> getAlternativeFlow() {
		if (alternativeFlow == null) {
			alternativeFlow = new EObjectContainmentEList<AlternativeFlow>(AlternativeFlow.class, this, TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW);
		}
		return alternativeFlow;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public BasicFlow getBasicScenario() {
		if (basicScenario == null){
			BasicFlow basic = TestcasetoolFactory.eINSTANCE.createBasicFlow();
			setBasicScenario(basic);
		}
		return basicScenario;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBasicScenario(BasicFlow newBasicScenario, NotificationChain msgs) {
		BasicFlow oldBasicScenario = basicScenario;
		basicScenario = newBasicScenario;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__BASIC_SCENARIO, oldBasicScenario, newBasicScenario);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBasicScenario(BasicFlow newBasicScenario) {
		if (newBasicScenario != basicScenario) {
			NotificationChain msgs = null;
			if (basicScenario != null)
				msgs = ((InternalEObject)basicScenario).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TestcasetoolPackage.USE_CASE__BASIC_SCENARIO, null, msgs);
			if (newBasicScenario != null)
				msgs = ((InternalEObject)newBasicScenario).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TestcasetoolPackage.USE_CASE__BASIC_SCENARIO, null, msgs);
			msgs = basicSetBasicScenario(newBasicScenario, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__BASIC_SCENARIO, newBasicScenario, newBasicScenario));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getPreCondition() {
		return preCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPreCondition(String newPreCondition) {
		String oldPreCondition = preCondition;
		preCondition = newPreCondition;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__PRE_CONDITION, oldPreCondition, preCondition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getPostCondition() {
		return postCondition;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPostCondition(String newPostCondition) {
		String oldPostCondition = postCondition;
		postCondition = newPostCondition;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TestcasetoolPackage.USE_CASE__POST_CONDITION, oldPostCondition, postCondition));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Actor> getParticipantActor() {
		if (participantActor == null) {
			participantActor = new EObjectWithInverseResolvingEList.ManyInverse<Actor>(Actor.class, this, TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR, TestcasetoolPackage.ACTOR__USE_CASE);
		}
		return participantActor;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getParticipantActor()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW:
				return ((InternalEList<?>)getAlternativeFlow()).basicRemove(otherEnd, msgs);
			case TestcasetoolPackage.USE_CASE__BASIC_SCENARIO:
				return basicSetBasicScenario(null, msgs);
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				return ((InternalEList<?>)getParticipantActor()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__NAME:
				return getName();
			case TestcasetoolPackage.USE_CASE__DESCRIPTION:
				return getDescription();
			case TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW:
				return getAlternativeFlow();
			case TestcasetoolPackage.USE_CASE__BASIC_SCENARIO:
				return getBasicScenario();
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				return getParticipantActor();
			case TestcasetoolPackage.USE_CASE__PRE_CONDITION:
				return getPreCondition();
			case TestcasetoolPackage.USE_CASE__POST_CONDITION:
				return getPostCondition();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__NAME:
				setName((String)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__DESCRIPTION:
				setDescription((String)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW:
				getAlternativeFlow().clear();
				getAlternativeFlow().addAll((Collection<? extends AlternativeFlow>)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__BASIC_SCENARIO:
				setBasicScenario((BasicFlow)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				getParticipantActor().clear();
				getParticipantActor().addAll((Collection<? extends Actor>)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__PRE_CONDITION:
				setPreCondition((String)newValue);
				return;
			case TestcasetoolPackage.USE_CASE__POST_CONDITION:
				setPostCondition((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case TestcasetoolPackage.USE_CASE__DESCRIPTION:
				setDescription(DESCRIPTION_EDEFAULT);
				return;
			case TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW:
				getAlternativeFlow().clear();
				return;
			case TestcasetoolPackage.USE_CASE__BASIC_SCENARIO:
				setBasicScenario((BasicFlow)null);
				return;
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				getParticipantActor().clear();
				return;
			case TestcasetoolPackage.USE_CASE__PRE_CONDITION:
				setPreCondition(PRE_CONDITION_EDEFAULT);
				return;
			case TestcasetoolPackage.USE_CASE__POST_CONDITION:
				setPostCondition(POST_CONDITION_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TestcasetoolPackage.USE_CASE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case TestcasetoolPackage.USE_CASE__DESCRIPTION:
				return DESCRIPTION_EDEFAULT == null ? description != null : !DESCRIPTION_EDEFAULT.equals(description);
			case TestcasetoolPackage.USE_CASE__ALTERNATIVE_FLOW:
				return alternativeFlow != null && !alternativeFlow.isEmpty();
			case TestcasetoolPackage.USE_CASE__BASIC_SCENARIO:
				return basicScenario != null;
			case TestcasetoolPackage.USE_CASE__PARTICIPANT_ACTOR:
				return participantActor != null && !participantActor.isEmpty();
			case TestcasetoolPackage.USE_CASE__PRE_CONDITION:
				return PRE_CONDITION_EDEFAULT == null ? preCondition != null : !PRE_CONDITION_EDEFAULT.equals(preCondition);
			case TestcasetoolPackage.USE_CASE__POST_CONDITION:
				return POST_CONDITION_EDEFAULT == null ? postCondition != null : !POST_CONDITION_EDEFAULT.equals(postCondition);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", description: ");
		result.append(description);
		result.append(", preCondition: ");
		result.append(preCondition);
		result.append(", postCondition: ");
		result.append(postCondition);
		result.append(')');
		return result.toString();
	}

} //UseCaseImpl
